package com.flowershop.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flowershop.entity.Flower;
import com.flowershop.mapper.FlowerMapper;
import com.flowershop.service.FlowerService;

@Service
public class FlowerServiceImpl extends ServiceImpl<FlowerMapper, Flower> implements FlowerService {
    
    @Override
    @Transactional
    public boolean updateStock(Long id, Integer quantity) {
        Flower flower = this.getById(id);
        if (flower == null || flower.getStock() < quantity) {
            return false;
        }
        
        flower.setStock(flower.getStock() - quantity);
        return this.updateById(flower);
    }
} 